﻿using CsvToSqlite;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        // 创建一个实现 IProcessingOutput 接口的类实例
        var output = new ConsoleOutput(); // 假设 ConsoleOutput 实现了 IProcessingOutput 接口

        // 创建 CsvDataImporter 实例
        var importer = new CsvDataImporter(output);

        // 配置 CSV 文件格式
        importer.ConfigureCsvFormat(',', true, "utf-8");

        // 设置列映射
        var columnMappings = new Dictionary<string, string>
        {
            { "CsvColumn1", "DbColumn1" },
            { "CsvColumn2", "DbColumn2" }
        };
        importer.SetColumnMappings(columnMappings);

        // 设置目标表信息
        importer.SetTargetTable("YourTableName", "YourPrimaryKey");

        // 导入数据
        var csvFilePath = "path/to/your/csv/file.csv";
        var dbFilePath = "path/to/your/sqlite/database.db";
        var importedCount = await importer.ImportAsync(csvFilePath, dbFilePath);

        Console.WriteLine($"成功导入 {importedCount} 条记录。");
    }
}

// 实现 IProcessingOutput 接口的类
class ConsoleOutput : IProcessingOutput
{
    public void OutputResult(ProcessingOutputDto outputDto)
    {
        if (outputDto.IsSuccess)
        {
            Console.WriteLine($"处理成功，导入了 {outputDto.ProcessedRecordCount} 条记录。");
            if (outputDto.AdditionalInfo.ContainsKey("Message"))
            {
                Console.WriteLine(outputDto.AdditionalInfo["Message"]);
            }
        }
        else
        {
            Console.WriteLine($"处理失败: {outputDto.ErrorMessage}");
            if (outputDto.AdditionalInfo.ContainsKey("StackTrace"))
            {
                Console.WriteLine(outputDto.AdditionalInfo["StackTrace"]);
            }
        }
    }
}